/**
 *  @author banxi1988
 */
     /**
      * 
      */
    var Tianya =  {};
    
    /**
     * 树容器.
     */
     Tianya.TreeNode = {};
     
      /**
       * 树节点类型,root,branch,leaf
       */
     Tianya.TreeNode.nodeTypes = { Root:0,Branch:1,Leaf:2};
         
     /**
       * 树节点状态 close,open
       */
     Tianya.TreeNode.nodeState = {close:0,open:1};
     
     
 
 
      Tianya.TreeNode.RootNode = {
    		  name:'',
    		  type:Tianya.TreeNode.nodeTypes.Root,
    		  state:Tianya.TreeNode.nodeState.open,
    		  childNodes:[]
      };
     
     /**
      * 根据,创建一个并报的节点.
      */
     Tianya.TreeNode.newNode = function(option){
    	 var option = option?option:{};
    	this.property = {
    	  code:option.code ?option.code:'1234',
    	  name:option.name?option:'new node',
    	  type:option.type?option.type:this.nodeTypes.Leaf,
    	  state:option.state?option.state:this.nodeState.close,
    	  clazz:'',
    	  parentId:0
    	
    	 };
    	this.childNodes = new Array();
    	this.parentNode = rootNode;
    	 isLeaf = function(){
    		 return property.type ==  this.nodeTypes.Leaf;
    	 };
    	 isRoot = function(){
    		 return property.type == this.nodeTypes.Root;
    	 };
    	 isBranch = function(){
    		return  property.type == this.nodeTypes.Branch; 
    	 };
    	 isMainCategory = function(){
    		 return parentId == 0 || parentId == '';
    	 };
    	 setType = function(type){
    		property.type = type;
    	 };
    	 setState = function(state){
    		 property.state = state;
    	 };
    	 setName = function(name){
    		 property.name = name;
    	 };
    	 setCategoryCode = function(code){
    		 property.code = code;
    	 };
    	 setClazz = function(clazz){
    		 property.clazz = clazz;
    	 };
    	 setParentId = function(parentId){
    		 property.parentId = parentId;
    	 };
    	 addChild = function(childNode){
    		 if(typeof childNode != Tianya.TreeNode.newNode );
    		 else{
    		  this.childNodes.push(childNodes);
    		  this.childNodes.parentNode = this;
    		 }
    		 
    		
    	 };
     };
     